package cn.com.zetatech.loader.util;

import cn.com.zetatech.loader.resolver.service.EnumFileParserStrategy;
import cn.com.zetatech.loader.resolver.service.impl.EnumCSVFileParser;
import cn.com.zetatech.loader.resolver.service.impl.EnumJSONFileParser;

import java.util.List;

/**
 * @author jian.chen@zetatech.com.cn
 * @Description TODO
 * @Date 2024/8/26 20:02
 */
public enum EnumFileParserType implements EnumFileParserStrategy {
    CSV {
        @Override
        public List<?> parse(String filePath) {
            return new EnumCSVFileParser().parse(filePath);
        }
    },
    JSON {
        @Override
        public List<?> parse(String filePath) {
            return new EnumJSONFileParser().parse(filePath);
        }
    };

    public static EnumFileParserType getParserByFileExtension(String extension) {
        switch (extension.toLowerCase()) {
            case "csv":
                return CSV;
            case "json":
                return JSON;
            default:
                throw new UnsupportedOperationException("Unsupported file extension: " + extension);
        }
    }
}

